package com.hd123.rumba.qt.def;

import java.io.IOException;
import java.io.Serializable;

import com.hd123.rumba.exception.BusinessException;

public class SQLOrder implements Serializable {
  public String getSQLExpression() throws BusinessException {
    StringBuffer sb = new StringBuffer();
    sb.append(query.getColumnByTitle(column));
    sb.append(" ");
    sb.append(order);
    return sb.length() == 0 ? null : sb.toString();
  }

  public String debugInfo() {
    StringBuffer sb = new StringBuffer();
    sb.append(getClass().getName() + "\n");
    sb.append("Column: " + getColumn() + "\n");
    sb.append("Order: " + getOrder() + "\n");
    return sb.toString();
  }

  private String column;
  private String title;
  private String order;

  public synchronized String getTitle() {
    return title;
  }

  public synchronized void setTitle(String title) {
    this.title = title;
  }

  public String getColumn() {
    return column;
  }

  public void setColumn(String column) {
    this.column = column;
  }

  public String getOrder() {
    return order;
  }

  public void setOrder(String order) {
    this.order = order;
  }

  private QueryDefinition query;

  public QueryDefinition getQuery() {
    return query;
  }

  public void setQuery(QueryDefinition query) {
    this.query = query;
  }

  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.writeObject(column);
    out.writeObject(order);
    out.writeObject(title);
  }

  private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    column = (String) in.readObject();
    order = (String) in.readObject();
    title = (String) in.readObject();
  }

}
